package com.hjq.fcloud.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import com.hjq.fcloud.http.api.FaceConfirmApi
import com.hjq.fcloud.http.model.HttpData
import com.hjq.fcloud.other.QrCodeParse
import com.hjq.fcloud.utils.BitmapUtils
import com.hjq.http.EasyHttp
import com.hjq.http.listener.HttpCallback

/**
 * 人脸确认-界面
 */
class FaceConfirmActivity : FaceDetectRGBActivity() {

    companion object {
        fun launcher(context: Context, bundle: Bundle? = null) {
            var intent = Intent(context, FaceConfirmActivity::class.java)
            if (bundle != null) {
                intent.putExtras(bundle)
            }
            context.startActivity(intent)
        }
    }

    override fun compareFace(url: String, filePath: String) {
        var step_token = getString(QrCodeParse.INTENT_IN_STEP_TOKEN)

        var api = FaceConfirmApi()
            .setAuth_pic(url)
            .setAuth_pic_base64(BitmapUtils.imageToBase64(filePath))
            .setStep_token(step_token)
        EasyHttp.post(this)
            .api(api)
            .request(object : HttpCallback<HttpData<FaceConfirmApi.Result>?>(this) {
                override fun onSucceed(data: HttpData<FaceConfirmApi.Result>?) {
                    showToast(data?.getMessage())
                    finish()
                }

                override fun onFail(e: Exception?) {
                    showCompareFailDialog(e?.message)
                }
            })
    }
}